home *** CD-ROM | disk | FTP | other *** search
- Path: crc-news.doc.ca!usenet
- From: don@mars.dgrc.doc.ca (Donald McLachlan)
- Newsgroups: comp.lang.c
- Subject: Re: f;oating point precision
- Date: 6 Mar 1996 14:33:41 GMT
- Organization: The Communications Research Centre
- Message-ID: <4hk7o5$gmk@crc-news.doc.ca>
- References: <4hit8c$8lm@news.microsoft.com>
- Reply-To: don@mars.dgrc.doc.ca
- NNTP-Posting-Host: gizmo.dgrc.doc.ca
-
- An even simpler example of the problem. The nice simple number .1 base10 cannot
- be *exactly* represented as a binary number. My simple way of converting from
- base10 decimals to binary is:
-
- 1. initialise the result string with a decimal point.
-
- .
-
- 2. take the base10 number (.1) and multiply by 2 (= 0.2) and append the digit on the
- left of the decimal point to the result in step 1.
-
- .0
-
- 3. Remove the digit to the left of the decimal point (.2). If the number is still
- != 0, repeat steps 2 and 3.
-
- For .1 base10, the process is:
-
- math result
- .1 * 2 = 0.2 .0
- .2 * 2 = 0.4 .00 <----------------
- .4 * 2 = 0.8 .000 |
- .8 * 2 = 1.6 .0001 |
- .6 * 2 = 1.2 .00011 |
- .2 * 2 = 0.4 *** we have seen this case before, so we are in an infinite
- loop (what is this called, and irrational number?) ***
-
- --
- Donald McLachlan e-mail donald.mclachlan@crc.doc.ca
- Communications Research Centre / DRX office 613-998-2845
- 3701 Carling Ave., fax 613-998-9648
- Ottawa, Ontario labs 613-998-2423 / 613-998-4118
- K2H 8S2 home 613-599-6262
- Canada
-
-
-
-
-